Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(notification-center,node,shared): update the axios to latest version #3861

Merged
merged 1 commit into from
Jul 27, 2023

Conversation

LetItRock
Copy link
Contributor

What change does this PR introduce?

Fixes the original issue from the ticket and additionally:

  • update the axios library to latest for: shared, node, notification-center
  • update the notification-center bundle config: use webpack for umd, tsc for esm and cjs
  • remove svg and webp images, instead use React SVG components

Verified if the @novu/node package works in:

  • NextJS app
  • NodeJS + Express app

Verified if the @novu/notification-center package works in:

  • Vite React app
  • NextJS / Remix
  • Our web app

Verified if the @novu/notification-center-vue and @novu/notification-center-angular packages works.

Why was this change needed?

Other information (Screenshots)

@LetItRock LetItRock self-assigned this Jul 26, 2023
@linear
Copy link

linear bot commented Jul 26, 2023

NV-2614 nodejs sdk is returning binary data response.

What?

On using nodejs sdk methods in express project, it returns binary data response like

image.png

It works perfect in nestjs project

Why? (Context)

novu/node has a dependency on novu/shared which uses an old version of axios. 1.2.0

Definition of Done

node SDK should not return this binary response in express project

@@ -26,7 +26,7 @@
"dist/"
],
"dependencies": {
"axios": "1.2.0",
"axios": "^1.4.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the Axios version 1.2.0 was buggy, updating it to the latest helped solve the original issue, but...

Comment on lines +10 to +16
"build": "npm run build:cjs && npm run build:esm && npm run build:umd && npm run build:types",
"build:cjs": "cross-env node_modules/.bin/tsc -p tsconfig.json",
"build:esm": "cross-env node_modules/.bin/tsc -p tsconfig.esm.json",
"build:esm:watch": "cross-env node_modules/.bin/tsc -p tsconfig.esm.json -w --preserveWatchOutput",
"build:umd": "webpack --config webpack.config.js",
"build:types": "tsc --declaration --emitDeclarationOnly --declarationMap --declarationDir dist/types -p tsconfig.json",
"build:watch": "rollup -c -w",
"build:watch": "npm run build:esm:watch",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That latest Axios version broke the UMD build of the notification-center package.
First of all, Rollup was bundling the Axios for node env, which required to polyfill NodeJS native modules like http, utils, ... etc.
The second thing was that the Rollup NodeJS polyfills do not support everything that Axios is using right now in Axios for node.
I wasn't able to figure out why it was trying to bundle the Axios for node, but I was sure that it was the issue between rollup plugins.

After a long fight, I decided to give it a try to Webpack, and in a few minutes, I had it working like a charm.
Then CJS and ESM modules needed to be built with TSC, but we were importing some images in the components, so I had to fix them too, like to make them React SVG components.

@@ -2,10 +2,10 @@ import React from 'react';
import { IMessage, ChannelCTATypeEnum } from '@novu/shared';

import { useNotifications, useNotificationCenter, useNovuContext, useTranslations } from '../../../hooks';
import image from '../../../images/no-new-notifications.svg';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've transformed svg and webp images to React SVG components

Comment on lines +1 to +7
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "ESNext",
"outDir": "./dist/esm"
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

separate TS config for the ESM module

"forceConsistentCasingInFileNames": true,
"target": "es6",
"strict": true,
"typeRoots": ["./node_modules/@types"],
"jsx": "react",
"module": "ESNext",
"module": "commonjs",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TS config for CJS

@scopsy scopsy added this pull request to the merge queue Jul 27, 2023
Merged via the queue into next with commit e2813b2 Jul 27, 2023
34 checks passed
@scopsy scopsy deleted the nv-2614-fix-axios-issue branch July 27, 2023 06:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants